package com.carltechnology.mahjonggamecaculation.utils.views;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.carltechnology.mahjonggamecaculation.R;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by WZTCM on 2016/6/7.
 */
public class TextEditView extends LinearLayout {
    private Context mContext;
    @InjectView(R.id.aids_text_input_view_text)
    TextView textView;
    @InjectView(R.id.aids_text_input_view_edit)
    EditText editText;

    public void setEditContent(String content){
        editText.setText(content);
    }
    public String getEditTextContent() {
        return editText.getText().toString();
    }
    public void setEditTextTag(String content){
        textView.setText(content);
    }
    public void setEditTextHint(String content) {
        editText.setHint(content);
    }

    public TextEditView(Context context) {
        super(context);
        initView(context);

    }

    public EditText getEditText() {
        return editText;
    }

    public TextEditView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextEditView);
        boolean bNumber = false;
        try {
            textView.setText(a.getString(R.styleable.TextEditView_textContent));
            editText.setHint(a.getString(R.styleable.TextEditView_editContent));
            bNumber = a.getBoolean(R.styleable.TextEditView_typeNumber,false);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            a.recycle();
        }
        if (bNumber){
            editText.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED|InputType.TYPE_CLASS_NUMBER);
        }
    }

    public TextEditView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public TextEditView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView(context);
    }

    private void initView(Context context) {
        View view = View.inflate(context, R.layout.aids_text_edit_input_view, this);
        ButterKnife.inject(this, view);
    }
}
